/*
 *   Copyright 1999-2016 Asiainfo Technologies(China),Inc.
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *        http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 */

package com.asiainfo.redis.entity;

import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @version v 1.0 on 2016/3/3 15:47
 * @auther william.xu
 */

@Entity
@Table(name="REDIS_CLUSTER_NODE")
@SequenceGenerator(name="REDIS_CLUSTER_NODE_SEQ_",sequenceName="REDIS_CLUSTER_NODE_SEQ",allocationSize=1)
public class ClusterNode {

    @Id
    @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="REDIS_CLUSTER_NODE_SEQ_")
    @Column(name = "ID")
    private Long id;

    @Column(name = "CLUSTER_ID")
    private Long clusterId;

    @Column(name = "HOST_ID")
    private Long hostId;

    @Column(name = "PORT")
    private Integer port;

    @Column(name = "IP")
    private String ip;

    @Transient
    private List<ClusterNode> slaveNodes;

    @Transient
    private Map<String, ClusterNode> slaveNodesMap;

    @Transient
    private String nodeId;

    @Transient
    private Set<Integer> slots;//数据量太多，暂时不返回到客户端了
    @Transient
    private Integer slotsLength;

    @Transient
    private String state;

    @Transient
    private String noFailover;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getClusterId() {
        return clusterId;
    }

    public void setClusterId(Long clusterId) {
        this.clusterId = clusterId;
    }

    public Long getHostId() {
        return hostId;
    }

    public void setHostId(Long hostId) {
        this.hostId = hostId;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public List<ClusterNode> getSlaveNodes() {
        return slaveNodes;
    }

    public void setSlaveNodes(List<ClusterNode> slaveNodes) {
        this.slaveNodes = slaveNodes;
    }

    public Map<String, ClusterNode> getSlaveNodesMap() {
        return slaveNodesMap;
    }

    public void setSlaveNodesMap(Map<String, ClusterNode> slaveNodesMap) {
        this.slaveNodesMap = slaveNodesMap;
    }

    public Set<Integer> getSlots() {
        return slots;
    }

    public void setSlots(Set<Integer> slots) {
        this.slots = slots;
    }

    public Integer getSlotsLength() {
        return slotsLength;
    }

    public void setSlotsLength(Integer slotsLength) {
        this.slotsLength = slotsLength;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getNodeId() {
        return nodeId;
    }

    public void setNodeId(String nodeId) {
        this.nodeId = nodeId;
    }

    public String toString(){
        return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
    }

    public String getNoFailover() {
        return noFailover;
    }

    public void setNoFailover(String noFailover) {
        this.noFailover = noFailover;
    }
}
